package com.gw.vip.server.controller;

import com.gw.vip.common.log.PrintlnLog;
import com.gw.vip.common.vo.Result;
import com.gw.vip.server.dto.*;
import com.gw.vip.server.sign.RequiredSign;
import com.gw.vip.server.vo.*;
import com.gw.vip.server.service.MainService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author GW
 * @description 主账户交易
 * @since 2022-04-26
 */
@RestController
@RequestMapping("main")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MainController {

    private final MainService mainService;

    @PrintlnLog(description = "主账户充值")
    @PostMapping("charge")
    @RequiredSign
    public Result charge(@RequestBody @Valid ChargeDto dto){
        MainAccResponse vo = mainService.charge(dto);
        return Result.success(vo);
    }

    @PrintlnLog(description = "主账户消费")
    @PostMapping("sale")
    @RequiredSign
    public Result sale(@RequestBody @Valid SaleDto dto){
        MainAccResponse vo = mainService.sale(dto);
        return Result.success(vo);
    }

    /**
     * 不支持部分退款
     * @param dto
     * @return
     */
    @PrintlnLog(description = "主账户退款")
    @PostMapping("refund")
    @RequiredSign
    public Result refund(@RequestBody @Valid RefundDto dto){
        MainAccResponse vo = mainService.refund(dto);
        return Result.success(vo);
    }

    @PrintlnLog(description = "主账户余额查询")
    @PostMapping("amtQuery")
    @RequiredSign
    public Result amtQuery(@RequestBody @Valid AmtQueryDto dto){
        AmtQueryVo vo = mainService.amtQuery(dto);
        return Result.success(vo);
    }
}
